#!/bin/bash
##################################################################
## function: delete hadoop flume  log 保留近7天的非压缩原始日志
## eg：./del_flume_log.sh  20150918
## author: shx
## createdate: 20150914
## version:     
################################################################## 
. /home/hadoop/shx/baseUtil.sh


if [[ ! -n "$1" ]] && [[ ! -n "$2" ]] ;then
	startDate=`date -d '-7 days'  +%Y%m%d`
  endDate=`date -d '-7 days'  +%Y%m%d`
else
	startDate=$1
  endDate=$2
fi


#获取时间循环列表
startSec=`date -d "$startDate" "+%s"`
endSec=`date -d "$endDate" "+%s"`

for((i=startSec;i<=endSec;i+=86400)); do
    curdate=`date -d "@$i" "+%Y%m%d"`
    echo $curdate

    /usr/local/cloud/hadoop/bin/hadoop fs -rmr /flume/original/api_response/$curdate
    /usr/local/cloud/hadoop/bin/hadoop fs -rmr /flume/original/apptrack/$curdate
    /usr/local/cloud/hadoop/bin/hadoop fs -rmr /flume/original/track/$curdate
    /usr/local/cloud/hadoop/bin/hadoop fs -rmr /flume/original/timecost/$curdate

done

if [ $? -eq 0 ]
  then
  	echo `date`"===============  delete hadoop flume  log is ok  end===============" 
else
  	echo `date`"================ delete hadoop flume  log is error end !================" 
  	mailSend "143 : delete hadoop flume  log error end !"
fi








